package com.yuexun.beilunpatient.ui.my.presenter.impl;

import com.yuexun.beilunpatient.ui.my.bean.MessageInfoBean;
import com.yuexun.beilunpatient.ui.my.model.IMessageModel;
import com.yuexun.beilunpatient.ui.my.presenter.IMessagePresenter;
import com.yuexun.beilunpatient.ui.my.ui.view.IMessageView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/11/23.
 */
public class MessagePresenter implements IMessagePresenter {
    private IMessageView view;
    private IMessageModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public MessagePresenter(IMessageModel model, IMessageView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getMessageList(Map<String, String> praise) {
        model.getMessageList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MessageInfoBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("消息列表获取失败");
                    }

                    @Override
                    public void onNext(MessageInfoBean messageInfoBean) {
                      view.showMessage(messageInfoBean);
                    }
                });
    }

}
